package 排序;

import java.util.Arrays;

public class 选择排序 {
    // 由小到大
    private static void sort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int current = nums[i];//最小数
            int p = i;//与i相互交互的位置
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] < current) {
                    current = nums[j];
                    p = j;
                }
            }
            if (p != i) {
                // 交换
                nums[p] = nums[i];
                nums[i] = current;
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {3, 4, 51, 2, 5, 4576, 3, 4, 234, 7, 89};
        sort(ints);
        System.out.println(Arrays.toString(ints));
    }
}
